from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from time import sleep

url = 'https://imooc.com'
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--window-size=1920,1080")
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get(url)


elements_a = driver.find_elements(By.XPATH, './/div[@class="bg000"]//div[@data-type="推荐"]/a')
for index, element in enumerate(elements_a, start=1):
    item = {}
    item['title'] = element.get_attribute('data-title')
    item['number'] = element.find_element(By.CLASS_NAME, 'difficulty').text
    item['price'] = element.find_element(By.CLASS_NAME, 'price').text
    item['origin-price'] = element.find_element(By.CLASS_NAME, 'origin-price').text
    print(index, item)


sleep(5)
driver.quit()

